#!/usr/bin/python
# -*- coding: cp1250 -*-

from pepe.glib import *
import shutil

def char_generator(wide=3):
    """ Character generator
    """
    for a in string.letters[:26]:
        for b in string.letters[:26]:
            for c in string.letters[:26]:
                yield string.lower("%s%s%s" % (a,b,c))

def main(filemask, start='aaa'):
    print '''
    rename abc'''
    chg = char_generator()
    abc = chg.next()
    
    #while abc <= start:
    #print start, abc
    while start > abc:
        #print start, abc
        abc = chg.next()

    for f in sorted(glob.glob(filemask)):
        #shutil.move(f, "%s-%s_RENABC" % (abc, f))
        #shutil.copy(f, "%s-%s_RENABC" % (abc, f))
        #shutil.move(f, "%s-%s_" % (abc, f))
        
        fdirfname = string.split(fw_slash(f), '/')
        if len(fdirfname) > 1:
            fdir = string.join(fdirfname[:-1], '/')
            fname = fdirfname[-1]
        else:
            fdir = ''
            fname = f
        #print "%s%s_%s_" % (fdir, abc, fname)
        shutil.copy(f, "%s%s_%s_" % (fdir, abc, fname)) # do not use '-' because this in name does not load to pg
        abc = chg.next()

if __name__ == "__main__":
    """ """
    if len(sys.argv) == 2:
        main(filemask=sys.argv[1])
    elif len(sys.argv) == 3:
        main(filemask=sys.argv[1], start=sys.argv[2])
    else:
        print 'Something is wrong. Try again now.'
